﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>书籍列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '修改',
	        iconCls: 'icon-edit',
	        handler: function () {  $('#dd').dialog('open');}
	    }, '-', {
	        text: '启用',
	        iconCls: 'icon-ok',
	        handler: function () { var row=$("#booklist").datagrid("getSelected");
                console.log(row);
                if(row==null){
                    alert("请选中数据行");
                }else if(row.flag==1){
                    alert("状态已启用");
                }else{
                    $.ajax({
                        url:"/manager/book/EnableFlag",
                        type:"post",
                        data:{"isbn":row.isbn},
                        dataType:"json",
                        success:function (result) {
                            if(result.status==2001){
                                $("#booklist").datagrid("reload");
                            }

                        }
                    })
                }
	        }
	    }, '-', {
	        text: '禁用',
	        iconCls: 'icon-cancel',
	        handler: function () { var row=$("#booklist").datagrid("getSelected");
                console.log(row);
                if(row==null){
                    alert("请选中数据行");
                }else if(row.flag==0){
                    alert("状态已禁用");
                }else{
                    $.ajax({
                        url:"/manager/book/DisEnableFlag",
                        type:"post",
                        data:{"isbn":row.isbn},
                        dataType:"json",
                        success:function (result) {
                            if(result.status==2001){
                                $("#booklist").datagrid("reload");
                            }

                        }
                    })
                }
	        }
	    }];


        $.ajax({
            url:"/manager/book/findSupplier",
            type:"post",
            data:"",
            dataType:"json",
            success:function(result){
                if(result.responseCode=="2001"){
                    let supplierList=result.returnValue;
                    $("#findSupplier").empty();
                    $("#findSupplier").append("<option value=\"\" selected>请选择供应商</option>");
                    for(let index in supplierList){
                        let txt="<option value=\""+supplierList[index].id+"\">"+supplierList[index].name+"</option>";
                        $("#findSupplier").append(txt);
                    }
                }
            },
            error:function () {
                alert("请求发送失败或响应异常");
            }
        });


        $(function(){
	       $('#booklist').datagrid({  
				title:'书籍列表',  
				iconCls:'icon-save',   
				url:'/manager/book/findBookAll',
				columns:[
				    [
					{field:'bookname',title:'名称',width:100,align:'center'},
					{field:'author',title:'作者',width:120,align:'center'},
					{field:'price',title:'单价',width:80,align:'center'},
					{field:'isbn',title:'ISBN',width:200,align:'center'},
					{field:'press',title:'出版社',width:200,align:'center',formatter:function (value,row,index) {
                            if (row.press){
                                return row.press.name;
                            } else {
                                return value;
                            }
                        }},
                        {field:'suppliers.name',title:'供货商',width:500,align:'center',formatter:function (value,row,index) {
                            console.log(row.suppliers);
                                if (row.suppliers){
                                    let namestr="";
                                    console.log(row.suppliers.length);
                                    for (let i = 0; i <row.suppliers.length;i++){
                                        namestr+=row.suppliers[i]==null ? "" : row.suppliers[i].name;
                                        if(i!=row.suppliers.length-1){
                                            namestr+=","
                                        }
                                    }
                                    return namestr;

                                } else {
                                    return value;
                                }
                            }},
                        {field:'flag',title:'状态',width:100,align:'center',
                            formatter:function (value,row,index) {
                                if(row.flag == 1){
                                    return "启用";
                                }else
                                    return "禁用";
                            }}

                    ]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#booklist').datagrid("reload",{
                        bookname:$("#bookname").val(),
                        isbn:$("#isbn").val(),
                        pressid:$("#pressid").val(),
                        supplierid:$("#supplierid").val()
                    }
                );   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        alert('ok');
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
			});
            
	   });


        $.ajax({
            url:"/manager/book/findPress",
            type:"post",
            data:'',
            dataType:'json',
            success:function (result) {
                if(result.status==2001){
                    let list=result.data;
                    for(let i=0;i<list.length;i++){

                        let txt = list[i].name;
                        let val = list[i].id;
                        let opt = new Option(txt, val);
                        $("#pressid").append(opt);
                    }
                }
            }

        });

        $.ajax({
            url:"/manager/book/findSupplier",
            type:"post",
            data:'',
            dataType:"json",
            success:function (result) {
                if (result.status == 2001) {
                    let list = result.data;
                    for (let i = 0; i < list.length; i++) {

                        let txt = list[i].name;
                        let val = list[i].id;
                        let opt = new Option(txt, val);
                        $("#supplierid").append(opt);
                    }
                }
            }
        });

    </script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>书籍查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" size=20 id="bookname" placeholder="书籍名称"/>
        <input type="text" name="keyword" size=20 id="isbn" placeholder="ISBN"/>
        <select name="press" id="pressid" >
            <option value="-1">请选择出版社</option>

        </select>
        <select name="supplier" id="supplierid" >
            <option value="-1">请选择供应商</option>
        </select>
        编辑推荐:<input type="checkbox" name="" value=""/>
        本周精选:<input type="checkbox" name="" value=""/>
    </td>
	<td>
	  <a id="submit_search">搜索</a>
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="name" style="width:50%" data-options="label:'书籍名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="email" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="subject" style="width:50%" data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
               封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  type="file"/>
            </div>
            <div style="margin-bottom:20px">
               编辑推荐:<input type="checkbox" name="" value=""/>
               本周精选:<input type="checkbox" name="" value=""/>
            </div>
            
        </form>
           </div>
    </div>
</body>
</html>